package com.hm.PushCaseService.service.valve;

import com.hm.PushCaseService.mapper.push.valve.ValveMapper;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import java.util.HashMap;


@Service
public class ValveService implements IValveService {

    @Qualifier("MainSqlSessionFactory")
    private final SqlSessionFactory sqlSessionFactory;

    public ValveService(SqlSessionFactory sqlSessionFactory) {
        this.sqlSessionFactory = sqlSessionFactory;
    }

    @Override
    public String queryValveState() {
        try (SqlSession session = sqlSessionFactory.openSession(true)) {
            ValveMapper mapper = session.getMapper(ValveMapper.class);
            return mapper.queryValveState(null);
        }
    }

    @Override
    public void setValveState(String status) {
        try (SqlSession session = sqlSessionFactory.openSession(true)) {
            ValveMapper mapper = session.getMapper(ValveMapper.class);
            HashMap<String, String> params = new HashMap<>();
            //status:0->打开 1->关闭
            params.put("status", status);
            mapper.setValveState(params);
        }
    }
}
